/*
 *
 *  * Copyright (c) 2021 Ones Authors. All Rights Reserved.
 *  *
 *  * Licensed under the Apache License, Version 2.0 (the "License");
 *  * you may not use this file except in compliance with the License.
 *  * You may obtain a copy of the License at
 *  *
 *  *     http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  * Unless required by applicable law or agreed to in writing, software
 *  * distributed under the License is distributed on an "AS IS" BASIS,
 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  * See the License for the specific language governing permissions and
 *  * limitations under the License.
 *
 */

package com.ones.sdp.common.core.constant;

import java.util.Arrays;
import java.util.Optional;

/**
 * core常量
 * @author Clark
 * @version 2021/04/02
 */
public interface CoreConsts {

    /**
     * 结果标识枚举类
     */
    enum ResCode {
        /**
         * 成功标记：0
         */
        SUCCESS(0, "操作成功"),
        /**
         * 失败标记：1
         */
        FAIL(-1, "操作失败");
        /**
         * 结果标识
         */
        private final int code;
        /**
         * 描述
         */
        private final String msg;

        ResCode(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static ResCode valueOf(int val) {
            Optional<ResCode> search = Arrays.stream(values()).filter((res) -> res.code == val).findFirst();
            return search.orElse(FAIL);
        }
        /**
         * 获取结果标识
         * @return 结果标识
         */
        public int getCode() {
            return this.code;
        }

        /**
         * 获取结果消息
         * @return 结果消息
         */
        public String getMsg() {
            return this.msg;
        }
    }
}
